import LContainer from '../layout/LayoutView.vue'
import LMain from '../layout/components/LMain/LMain.vue'

//匹配相应路径的所有文件
const modules = import.meta.glob('../views/**/*.vue')

const getPageComp = (path: string) => {
  return modules[`../views/${path}.vue`] || modules[`../views/error/ErrorDeveloping.vue`]
}

const defaultRoutesArr = [
  {
    name: 'Account',
    desc: '账号Router',
    path: 'account',
    children: [
      {
        name: 'Router',
        desc: '账号Router',
        path: '/AccountRouter',
      },
      {
        name: 'Login',
        desc: '登录页',
        path: '/login/LoginPage',
      },
      {
        name: 'Register',
        desc: '注册页',
        path: '/register/RegisterPage',
      },
      {
        name: 'Forget',
        desc: '忘记密码页',
        path: '/forget/ForgetPage',
      },
      {
        name: 'Lock',
        desc: '锁屏页',
        path: '/lock/LockPage',
      },
      {
        name: 'Redirect',
        desc: '回调页',
        path: '/redirect/RedirectPage',
      },
    ],
  },
  {
    name: 'Admin',
    desc: '个人中心',
    path: 'admin',
    children: [
      {
        name: 'WelPage',
        desc: '首页',
        path: '/wel/WelPage',
      },
      {
        name: 'PersonalPage',
        desc: '个人中心',
        path: '/personal/PersonalPage',
      },
      {
        name: 'SettingPage',
        desc: '个人设置',
        path: '/setting/SettingPage',
      },
    ],
  },
  {
    name: 'Error',
    desc: '错误页',
    path: 'error',
    children: [
      {
        name: '403',
        desc: 'Error403',
        path: '/ErrorPage403',
      },
      {
        name: '404',
        desc: 'Error404',
        path: '/ErrorPage404',
      },
      {
        name: '500',
        desc: 'Error500',
        path: '/ErrorPage500',
      },
      {
        name: 'Blank',
        desc: 'ErrorBlank',
        path: '/ErrorBlank',
      },
      {
        name: 'Developing',
        desc: 'ErrorDeveloping',
        path: '/ErrorDeveloping',
      },
      {
        name: 'NewWindow',
        desc: 'ErrorNewWindow',
        path: '/ErrorNewWindow',
      },
    ],
  },
  {
    name: 'Idt',
    desc: '身份管理',
    path: 'idt',
    children: [
      {
        name: 'User',
        desc: '用户管理',
        path: '/user/UserPage',
      },
      {
        name: 'Org',
        desc: '组织管理',
        path: '/org/OrgPage',
      },
      {
        name: 'UserType',
        desc: '用户类型',
        path: '/userType/UserTypePage',
      },
      {
        name: 'OrgType',
        desc: '组织类型',
        path: '/orgType/OrgTypePage',
      },
      {
        name: 'Job',
        desc: '岗位管理',
        path: '/job/JobPage',
      },
      {
        name: 'Group',
        desc: '岗位管理',
        path: '/group/GroupPage',
      },
    ],
  },
  {
    name: 'Pow',
    desc: '权限管理',
    path: 'pow',
    children: [
      {
        name: 'Role',
        desc: '角色管理',
        path: '/role/RolePage',
      },
      {
        name: 'Menu',
        desc: '菜单管理',
        path: '/menu/MenuPage',
      },
      {
        name: 'MenuGroup',
        desc: '菜单分组',
        path: '/menuGroup/MenuGroupPage',
      },
      {
        name: 'Apiscope',
        desc: '接口权限',
        path: '/apiscope/ApiscopePage',
      },
      {
        name: 'Datascope',
        desc: '接口权限',
        path: '/datascope/DatascopePage',
      },
    ],
  },
  {
    name: 'Sys',
    desc: '系统管理',
    path: 'sys',
    children: [
      {
        name: 'Area',
        desc: '区域管理',
        path: '/area/AreaPage',
      },
      {
        name: 'Config',
        desc: '系统配置',
        path: '/config/ConfigPage',
      },
      {
        name: 'Dict',
        desc: '字典管理',
        path: '/dict/DictPage',
      },
      {
        name: 'Sms',
        desc: '短信管理',
        path: '/sms/SmsPage',
      },
      {
        name: 'Email',
        desc: '短信管理',
        path: '/email/EmailPage',
      },
      {
        name: 'Note',
        desc: '公告管理',
        path: '/note/NotePage',
      },
      {
        name: 'Log',
        desc: '日志管理',
        path: '/log/LogPage',
      },
    ],
  },
  {
    name: 'Dev',
    desc: '开发中心',
    path: 'dev',
    children: [
      {
        name: 'Datasource',
        desc: '数据源管理',
        path: '/datasource/DatasourcePage',
      },
      {
        name: 'Datatable',
        desc: '数据表管理',
        path: '/datatable/DatatablePage',
      },
    ],
  },
  {
    name: 'DemoApp',
    desc: '演示应用',
    path: 'demo/app',
    children: [
      {
        name: 'One',
        desc: '应用一',
        path: '/one/OnePage',
      },
      {
        name: 'Two',
        desc: '应用二',
        path: '/two/TwoPage',
      },
      {
        name: 'Three',
        desc: '应用三',
        path: '/three/ThreePage',
      },
    ],
  },
  {
    name: 'DemoTable',
    desc: '演示表格',
    path: 'demo/table',
    children: [
      {
        name: 'AdvancedTable',
        desc: '高级表格',
        path: '/advancedTable/AdvancedTable',
      },
      {
        name: 'TreeTable',
        desc: '树表格',
        path: '/treeTable/TreeTable',
      },
    ],
  },
]

const defaultRoutes = new Map()

// 容器
defaultRoutes.set('LContainer', LContainer) // 账户
defaultRoutes.set('LMain', LMain) // 账户

defaultRoutesArr.forEach((item) => {
  item.children.forEach((child) => {
    defaultRoutes.set(item.name + child.name, getPageComp(item.path + child.path))
  })
})

export { defaultRoutes }
